const express = require('express')
const app = express()

function postParams(req, res, next) {
    // console.log('处理post请求的中间件触发');
    let result = ''
    req.on('data', chunk => result += chunk)
    req.on('end', () => {
        const usp = new URLSearchParams(result)
        req.body = {
            name: usp.get('name'),
            id: usp.get('id')

        }
        next()
    })

}




app.use(postParams)


app.post('/add', (req, res) => {
    console.log(req.body);
    res.send('新增成功')
})


app.listen(8000, () => { console.log('8000开启成功'); })